package com.jacen.fzxs.service.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jacen.fzxs.dao.IBaseDao;
import com.jacen.fzxs.dao.IImageDao;
import com.jacen.fzxs.dao.IWallCustomerDao;
import com.jacen.fzxs.dao.IWallDao;
import com.jacen.fzxs.entity.WallCustomerEntity;
import com.jacen.fzxs.entity.WallEntity;
import com.jacen.fzxs.service.IWallService;
import com.jacen.fzxs.util.Constants;
import com.jacen.fzxs.web.Pager;

/**
 * 墙体Service
 * @author Jacen
 *
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class WallService extends BaseService<WallEntity> implements IWallService {
	
	@Resource
	private IWallDao wallDao;
	@Resource
	private IWallCustomerDao wallCustomerDao;
	@Resource
	private IImageDao imageDao;
	
	@Override
	public IBaseDao<WallEntity> getDao() {
		// TODO Auto-generated method stub
		return wallDao;
	}
	
	@Override
	@Transactional(readOnly = true)
	public List<Map<String, Object>> getPage(Pager pager, Map<String, String> params) throws SQLException {
		pager.setTotalCount(getCount(params));
		return wallDao.getPage( (pager.getCurPageNum() - 1) * pager.getPageSize(), pager.getPageSize(), params);
	}

	@Transactional(readOnly = true)
	public int getCount(Map<String, ? extends Object> params) throws SQLException {
		return wallDao.getCount(params);
	}

	@Override
	@Transactional(readOnly = true)
	public List<Map<String, Object>> getList(Map<String, String> params) {
		return wallDao.getList(params);
	}

	@Override
	@Transactional(readOnly = true)
	public WallEntity getEntity(String username, String tel) {
		return wallDao.getEntity(username, tel);
	}

	@Override
	public void deleteAndRel(String id) {
		// TODO Auto-generated method stub
		deleteById(id);
		WallCustomerEntity waEntity = wallCustomerDao.getByKey("wid", id);
		if (waEntity != null) {
			wallCustomerDao.delete(waEntity);
		}
		imageDao.deleteByKey("wid", id);
	}

	@Override
	public List<WallEntity> getEntityList(Map<String, String> params) {
		return wallDao.getEntityList(params);
	}

	@Override
	public List<WallEntity> getEntityList(Pager pager,
			Map<String, String> params) {
		String sql = "select * from t_wall ";
		return wallDao.getPage(sql, pager.getCurPageNum(), Constants.PAGE_SIZE, params);
	}

	@Override
	public List<WallEntity> getListPage(Pager pager, Map<String, String> params) {
		if(pager!=null){
			pager.setTotalCount(getListCount(params));
		}
		return wallDao.getListPage((pager.getCurPageNum() - 1) * pager.getPageSize(), pager.getPageSize(), params);
	}

	@Override
	public int getListCount(Map<String, String> params)  {
		return wallDao.getListCount(params);
	}
	
	

	

}
